{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>

<form class="layui-form" action="" id="cross_srh" lay-filter="cross_srh">
    <div class="layui-inline" >
        <div class="layui-input-inline">
                    <label class="layui-form-label">project_name：</label>
                    <div class="layui-input-inline">
                        <select class="layui-select" name="project_id" id="project_id" lay-verify="" lay-search
                                lay-filter="project_id">
                            <option value=''>请选择</option>
                            {% for d in projectAll %}
                                <option value="{{d.id}}">{{d.project_name}}</option>
                            {% endfor %}
                        </select>
                    </div>
        </div>
        <br><br>
        <div class="layui-input-inline">
                    <label class="layui-form-label">moudle_type：</label>
                    <div class="layui-input-inline">
                        <select class="layui-select" name="moudle_type" id="moudle_type" lay-verify="" lay-search
                                lay-filter="moudle_type">
                            <option value="1">供API使用</option>

                        </select>
                    </div>
                </div>
        <br><br>
        <div class="layui-input-inline">
                    <label class="layui-form-label">moudle_name：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="moudle_name" id="moudle_name" placeholder="请输入" style="width:212px">
                    </div>
        </div>
        <div class="layui-input-inline" style="display:none">

                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="id" id="id" placeholder="请输入" style="width:212px">
                    </div>
        </div>

                <button type="button" id="project_save" class="layui-btn">保存</button>
    </div>
</form>

<script>
    layui.use(['table','code'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          moudelDCase = layui.data('test').moudelDCase;
                if(moudelDCase == undefined){
                    id == "";
                }else{
                    form.val('cross_srh',{
                        id:moudelDCase.id,
                        project_id:moudelDCase.project_id,
                        moudle_type:moudelDCase.moudle_type,
                        moudle_name:moudelDCase.moudle_name
                    });
                }
          //点击添加页面
          $('#project_save').on('click',function(){

                if($('#moudle_name').val()!=""){
                    $.ajax({
                        //发出请求
                        type:"POST",
                        url:"/moudle/manage",
                        contentType: 'application/json; charset=utf-8',
                        dataType:"json",
                        data:JSON.stringify({"id":$('#id').val(),"project_id":$('#project_id option:selected').val(),"moudle_type":$('#moudle_type option:selected').val(),"moudle_name":$('#moudle_name').val()}),
                        success: function(result){
                            if(result.id){
                                layer.msg("保存成功!");

                            }else{
                                layer.msg("模块名称已经存在!");
                            }
                        }
                    });
                }else{
                    layer.msg("模块名称不能为空!");
                }
                return false;
          });

    });
</script>



{% endblock %}